#!/bin/bash

echo -e "\033[32m  choose docker version to install, example:"-20.10.6-3.el7",can use --> yum list docker-ce --showduplicates|sort -r \033[0m"
docker_version=""

echo -e "\033[32m  install some dependece \033[0m"
sudo yum install yum-utils device-mapper-persistent-data lvm2 -y

echo -e "\033[32m  add some params for installers \033[0m"
sudo wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

echo -e "\033[32m  update yum and then install Docker-CE \033[0m"
sudo yum install docker-ce docker-ce-cli -y

echo -e "\033[32m  change daemon.json position \033[0m"
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://wlainhm4.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF

echo -e "\033[32m  start and enable docker \033[0m"
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl enable docker

echo -e "\033[32m  show docker is installed suucessfully or not \033[0m"
if [ $? -eq 0 ];then
    echo -e "\033[1;32m Docker start successful. \033[0m"
else
    echo -e "\033[1;31m Docker start failed!please check! \033[0m"
fi
